package com.bringway.p2p.controller;

import java.io.OutputStream;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.excel.ExcelOperUtil;
import com.bringway.framework.excel.ExcelSheet;
import com.bringway.framework.util.RequestUtils;
import com.bringway.global.constant.ExcelHeadConstant;
import com.bringway.global.domain.SysUserDetails;
import com.bringway.p2p.service.POSService;

import net.sf.json.JSONObject;

/*
 * @ClassName: PosController
 * @Description: pos单号控制器
 * @author: 邵jing
 * @date: 2016年2月15日 下午3:17:54
 */
@Controller
@RequestMapping("/pos")
public class PosController extends JsonController {
	
	Logger logger = Logger.getLogger(PosController.class);
	
	@Autowired
	private POSService posService;
	/**
	 * @方法名称: savePosCode
	 * @方法描述: 保存pos单号的方法
	 * @时间:2016年2月15日下午3:22:46
	 * @author:邵jing
	 * @param request
	 * @param response
	 * @return null
	 * @throws Exception	
	 */
	@RequestMapping("/insertPosCode")
	public ModelAndView insertPosCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//获取参数
		String POS_CODE = RequestUtils.getStringParameter(request, "POS_CODE");
		String OPER_USER_ID = RequestUtils.getStringParameter(request, "OPER_USER_ID");
		String POS_OWNER_USER_ID = RequestUtils.getStringParameter(request, "POS_OWNER_USER_ID");
		String POS_OWNER_SJHM = RequestUtils.getStringParameter(request, "POS_OWNER_SJHM");
		String POS_CONTENT = RequestUtils.getStringParameter(request, "POS_CONTENT");
		String POS_MONEY = RequestUtils.getStringParameter(request, "POS_MONEY");
		String POS_BIZ_GYH = RequestUtils.getStringParameter(request,"POS_BIZ_GYH");
		
		String POS_PLATFORM = RequestUtils.getStringParameter(request,"POS_PLATFORM");
		String POS_CUSTOMER_SEX = RequestUtils.getStringParameter(request,"POS_CUSTOMER_SEX");
		String POS_CUSTOMER_SFZ = RequestUtils.getStringParameter(request,"POS_CUSTOMER_SFZ");
		String POS_CUSTOMER_HK_YHMC = RequestUtils.getStringParameter(request,"POS_CUSTOMER_HK_YHMC");
		String POS_CUSTOMER_HK_CARD_NUM = RequestUtils.getStringParameter(request,"POS_CUSTOMER_HK_CARD_NUM");
		String POS_CUSTOMER_LY = RequestUtils.getStringParameter(request,"POS_CUSTOMER_LY");
		//结果集
		JSONObject result = new JSONObject();
		//封装参数
		JSONObject parms = new JSONObject();
		parms.put("POS_CODE",POS_CODE);
		parms.put("OPER_USER_ID",OPER_USER_ID);
		parms.put("POS_OWNER_USER_ID",POS_OWNER_USER_ID);
		parms.put("POS_OWNER_SJHM",POS_OWNER_SJHM);
		parms.put("POS_CONTENT",POS_CONTENT);
		parms.put("POS_MONEY", POS_MONEY);
		parms.put("POS_BIZ_GYH", POS_BIZ_GYH);
		
		parms.put("POS_PLATFORM", POS_PLATFORM);
		parms.put("POS_CUSTOMER_SEX", POS_CUSTOMER_SEX);
		parms.put("POS_CUSTOMER_SFZ", POS_CUSTOMER_SFZ);
		parms.put("POS_CUSTOMER_HK_YHMC", POS_CUSTOMER_HK_YHMC);
		parms.put("POS_CUSTOMER_HK_CARD_NUM", POS_CUSTOMER_HK_CARD_NUM);
		parms.put("POS_CUSTOMER_LY", POS_CUSTOMER_LY);
		try{
			boolean isRealCustomer = this.posService.isRealCustomer(parms);
			if(isRealCustomer){
				boolean isExsitPoscode = posService.ishasPoscodeInfo(parms);
				if(isExsitPoscode){
					result.put("isSaveSuc", false);
					result.put("msg", "pos单号已存在，请勿重复录入！");
				}else{
					boolean isSaveSuc = posService.savePosCode(parms);
					if(isSaveSuc){
						result.put("isSaveSuc", true);
						result.put("msg", "客户信息匹配失败！");
					}else{
						result.put("isSaveSuc", false);
						result.put("msg", "保存失败！");
					}
				}
				
			}else{
				result.put("isSaveSuc", false);
				result.put("msg", "客户信息匹配失败！");
			}
		}catch(Exception e){
			e.printStackTrace();
			result.put("isSaveSuc", false);
			result.put("msg", "数据有误！");
		}
		
		result.put("success", true);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * @方法名称: searchPos
	 * @方法描述: 查询pos单号
	 * @时间:2016年2月16日上午10:23:44
	 * @author:邵jing
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/searchPos")
	public ModelAndView searchPos(HttpServletRequest request,HttpServletResponse response)throws Exception{
		String POS_CODE = RequestUtils.getStringParameter(request,"POS_CODE");
		String OPER_USER_ID = RequestUtils.getStringParameter(request,"OPER_USER_ID");
		String POS_OWNER_USER_ID = RequestUtils.getStringParameter(request,"POS_OWNER_USER_ID");
		String POS_OWNER_SJHM = RequestUtils.getStringParameter(request,"POS_OWNER_SJHM");
		String POS_STATE = RequestUtils.getStringParameter(request,"POS_STATE");
		String OPER_DATE_START = RequestUtils.getStringParameter(request,"OPER_DATE_START");
		String OPER_DATE_END = RequestUtils.getStringParameter(request,"OPER_DATE_END");
		double POS_MONEY_START = RequestUtils.getDoubleParameter(request, "POS_MONEY_START", 0.0);
		double POS_MONEY_END = RequestUtils.getDoubleParameter(request, "POS_MONEY_END", 0.0);
		String start = RequestUtils.getStringParameter(request, "start");
		String limit = RequestUtils.getStringParameter(request, "limit");
		JSONObject parms = new JSONObject();
		parms.put("POS_CODE", POS_CODE);
		parms.put("OPER_USER_ID", OPER_USER_ID);
		parms.put("POS_OWNER_USER_ID", POS_OWNER_USER_ID);
		parms.put("POS_OWNER_SJHM", POS_OWNER_SJHM);
		parms.put("POS_STATE", POS_STATE);
		parms.put("OPER_DATE_START", OPER_DATE_START);
		parms.put("OPER_DATE_END", OPER_DATE_END);
		parms.put("limit", limit);
		parms.put("start", start);
		parms.put("POS_MONEY_START", POS_MONEY_START);
		parms.put("POS_MONEY_END", POS_MONEY_END);
		List list = posService.searchPos(parms);
		int total = posService.getTotalItem(parms);
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", total);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * 
	 * @方法名称: posCodeShenHe
	 * @方法描述: pos单号审核信息查询
	 * @时间:2016年2月16日下午2:34:44
	 * @author:邵jing
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/posCodeShenHe")
	public ModelAndView posCodeShenHe(HttpServletRequest request,HttpServletResponse response)throws Exception{
		String POS_CODE = RequestUtils.getStringParameter(request, "POS_CODE");
		String OPER_USER_ID = RequestUtils.getStringParameter(request, "OPER_USER_ID");
		String POS_OWNER_USER_ID = RequestUtils.getStringParameter(request, "POS_OWNER_USER_ID");
		String POS_OWNER_SJHM = RequestUtils.getStringParameter(request, "POS_OWNER_SJHM");
		String POS_CONTENT = RequestUtils.getStringParameter(request, "POS_CONTENT"); 
		String SH_STATE = RequestUtils.getStringParameter(request, "SH_STATE");
		String TZSJ_START = RequestUtils.getStringParameter(request,"TZSJ_START");
		String TZSJ_END = RequestUtils.getStringParameter(request,"TZSJ_END");
		String start = RequestUtils.getStringParameter(request, "start");
		String limit = RequestUtils.getStringParameter(request, "limit");
		JSONObject parms = new JSONObject();
		parms.put("POS_CODE", POS_CODE);
		parms.put("OPER_USER_ID", OPER_USER_ID);
		parms.put("POS_OWNER_USER_ID", POS_OWNER_USER_ID);
		parms.put("POS_OWNER_SJHM", POS_OWNER_SJHM);
		parms.put("POS_CONTENT", POS_CONTENT);
		parms.put("SH_STATE", SH_STATE);
		parms.put("TZSJ_START",TZSJ_START);
		parms.put("TZSJ_END",TZSJ_END);
		parms.put("start", start);
		parms.put("limit", limit);
		List list = posService.posCodeInfoSearch(parms);
		JSONObject result = new JSONObject();
		result.put("data", list);
		int total = posService.posCodeInfoSearchItems(parms);
		result.put("total", total);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * @方法名称: savePosZBShenHe
	 * @方法描述: pos单号总部审核
	 * @时间:2016年3月21日下午5:48:33
	 * @author:邵jing
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/savePosZBShenHe")
	public ModelAndView savePosZBShenHe(HttpServletRequest request, HttpServletResponse response) throws Exception {
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String ID = RequestUtils.getStringParameter(request, "ID");
		String POS_ID = RequestUtils.getStringParameter(request,"POS_ID");
		String SH_STATE = RequestUtils.getStringParameter(request,"SH_STATE");
		String ZB_SH_CONTENT = RequestUtils.getStringParameter(request,"ZB_SH_CONTENT");
		JSONObject parms = new JSONObject();
		parms.put("userId", sysUserDetails.getGyh());
		parms.put("ZB_SH_CONTENT", ZB_SH_CONTENT);
		parms.put("SH_STATE", SH_STATE);
		parms.put("ID", ID);
		parms.put("POS_ID",POS_ID);
		boolean bool = posService.posZbShenHe(parms);
		JSONObject result = new JSONObject();
		result.put("success",true);
		result.put("isShenHeSuccess", bool);
		serialize(request, response, result);
		return null;
	}
	/**
	 * 
	 * @方法名称: savePosShenHe
	 * @方法描述: 审核pos单号
	 * @时间:2016年2月17日下午5:11:21
	 * @author:邵jing
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/savePosShenHe")
	public ModelAndView savePosShenHe(HttpServletRequest request,HttpServletResponse response)throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String ID = RequestUtils.getStringParameter(request, "ID");
		String POS_ID = RequestUtils.getStringParameter(request,"POS_ID");
		String SH_STATE = RequestUtils.getStringParameter(request,"SH_STATE");
		String SH_CONTENT = RequestUtils.getStringParameter(request,"SH_CONTENT");
		JSONObject parms = new JSONObject();
		parms.put("userId", sysUserDetails.getGyh());
		parms.put("SH_CONTENT", SH_CONTENT);
		parms.put("SH_STATE", SH_STATE);
		parms.put("ID", ID);
		parms.put("POS_ID",POS_ID);
		JSONObject result = new JSONObject();
		result.put("success",true);
		try{
			boolean isHasTzrxx = posService.isHasTzrxxByPoscode(parms);
			if(isHasTzrxx){//true 已经处理过
				result.put("isSaved",false);
				result.put("msg", "该pos单号已经审核且投资成功过，请勿重复操作！");
			}else{//新单子，新增
				boolean bool = posService.posShenHe(parms);
				result.put("isSaved",bool);
				result.put("msg", bool == true ? "操作成功！" : "操作失败！");
			}
		}catch(Exception e){
			e.printStackTrace();
			logger.info("savePosShenHe pos单号投资，审核失败！" + e.getMessage());
			result.put("isSaved",false);
			result.put("msg", "该pos单号操作失败！");
		}
		serialize(request, response, result);
		return null;
	}
	
	
	/**
	 * 
	 * @方法描述: 查询pos单投资待回款信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryPosCodeHkList")
	public ModelAndView queryPosCodeHkList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		String start = RequestUtils.getStringParameter(request, "start");
		String limit = RequestUtils.getStringParameter(request, "limit");
		String ZQHK_START = RequestUtils.getStringParameter(request, "ZQHK_START");
		String ZQHK_END = RequestUtils.getStringParameter(request, "ZQHK_END");
		String Hk_STATE = RequestUtils.getStringParameter(request, "Hk_STATE");
		String ZQ_ID = RequestUtils.getStringParameter(request, "ZQ_ID");
		String POS_PLATFORM_STATE = RequestUtils.getStringParameter(request, "POS_PLATFORM_STATE");
		String POS_CODE = RequestUtils.getStringParameter(request, "Q_POS_CODE");
		JSONObject params = new JSONObject();
		params.put("start", start);
		params.put("limit", limit);
		params.put("ZQHK_START", ZQHK_START);
		params.put("ZQHK_END", ZQHK_END);
		params.put("Hk_STATE", Hk_STATE);
		params.put("ZQ_ID", ZQ_ID);
		params.put("POS_PLATFORM_STATE", POS_PLATFORM_STATE);
		params.put("POS_CODE", POS_CODE);
		List<HashMap<String,String>> list = posService.queryPosCodeHkList(params);
		int count = posService.getPosCodeHkCount(params);
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	
	
	/**
	 * 
	 * @方法描述: 确认保存pos单投资回款，打款提现
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/savePosHk")
	public ModelAndView savePosHk(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String tzrxxId = RequestUtils.getStringParameter(request, "tzrxxId");
		String posCode = RequestUtils.getStringParameter(request, "posCode");
		String tzje = RequestUtils.getStringParameter(request, "tzje");
		String tzsyje = RequestUtils.getStringParameter(request, "tzsyje");
		String hkContent = RequestUtils.getStringParameter(request, "hkContent");
		JSONObject params = new JSONObject();
		params.put("tzrxxId", tzrxxId);
		params.put("posCode", posCode);
		params.put("tzje", tzje);
		params.put("tzsyje", tzsyje);
		params.put("hkContent", hkContent);
		params.put("hkUserId", sysUserDetails.getGyh());
		JSONObject result = new JSONObject();
		result.put("success",true);
		boolean isSuc = false;
		try{
			boolean isReadyHk = this.posService.isReadyHk(params);
			boolean isHasHk = this.posService.isHasHkByPoscode(params);
			if(isReadyHk){
				if(isHasHk){
					isSuc = false;
					result.put("msg","该记录已回款，请勿重复操作！");
				}else{
					this.posService.savePosHk(params);
					isSuc = true;
				}
			}else{
				isSuc = false;
				result.put("msg","还未到回款日，无法确认回款！");
			}
			
		}catch(Exception e){
			e.printStackTrace();
			isSuc = false;
			result.put("msg","处理失败！");
			logger.info("savePosHk pos单号投资，手动回款失败！"+ params.toString());
		}
		result.put("isSuc",isSuc);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * 
	 * @方法描述: 删除未验证的pos单信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/deletePos")
	public ModelAndView deletePos(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		String bizId = RequestUtils.getStringParameter(request, "bizId");
		params.put("bizId", bizId);
		params.put("gyh", sysUserDetails.getGyh());
		params.put("username", sysUserDetails.getUsername());
		try{
			Map<String,Object> posInfoMap = posService.getPosInfo(params);
			if(null !=posInfoMap){
				if(posInfoMap.containsKey("POS_STATE") && "00".equals(posInfoMap.get("POS_STATE"))){
					posService.deletePos(params);
					result.put("isDeleteSuc", true);
					result.put("msg", "删除成功!");
				}else{
					result.put("isDeleteSuc", false);
					result.put("msg", "对不起,您的操作不正确!");
				}
			}else{
				result.put("isDeleteSuc", false);
				result.put("msg", "对不起,信息不存在!");
			}
		}catch(Exception e){
			e.printStackTrace();
			result.put("isDeleteSuc", false);
			result.put("msg", "对不起,连接超时!");
			logger.info("deletePos 删除posinfo失败！"+ params.toString());
		}
		result.put("success", true);
		serialize(request,response,result);
		return null;
	}
	
	
	@RequestMapping("exportExcel")
	public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String ZQHK_START = RequestUtils.getStringParameter(request, "ZQHK_START");
		String ZQHK_END = RequestUtils.getStringParameter(request, "ZQHK_END");
		String Hk_STATE = RequestUtils.getStringParameter(request, "Hk_STATE");
		String ZQ_ID = RequestUtils.getStringParameter(request, "ZQ_ID");
		String POS_PLATFORM_STATE = RequestUtils.getStringParameter(request, "POS_PLATFORM_STATE");
		String POS_CODE = RequestUtils.getStringParameter(request, "Q_POS_CODE");
		String testCN = RequestUtils.getStringParameter(request, "testCN");
		testCN = URLDecoder.decode(testCN,"UTF-8");
		JSONObject params = new JSONObject();
		params.put("ZQHK_START", ZQHK_START);
		params.put("ZQHK_END", ZQHK_END);
		params.put("Hk_STATE", Hk_STATE);
		params.put("ZQ_ID", ZQ_ID);
		params.put("POS_PLATFORM_STATE", POS_PLATFORM_STATE);
		params.put("POS_CODE", POS_CODE);
		params.put("gyh", sysUserDetails.getGyh());
		params.put("queryType", "exportExcel");
		// 查询数据
		List<HashMap<String, String>>  posHkList = this.posService.queryPosCodeHkList(params);;
		List<String[]> dataList = ExcelHeadConstant.getPosHkExportSearchResultData(posHkList);
		// 导出数据到Excel文件
		List<ExcelSheet> sheetList = new ArrayList<ExcelSheet>();
		ExcelSheet sheet = new ExcelSheet();
		sheet.setBodyList(dataList);
		sheet.setSheetName("POS回款信息列表");
		sheetList.add(sheet);
		OutputStream os = response.getOutputStream();
		super.setDownLoadResponseHeader(request, response, "POS单投资回款信息列表.xls");
		response.setContentType("application/vnd.ms-excel");
		// 导出EXCEL
		ExcelOperUtil.writeExcel(sheetList, os);
	}
	
	/**
	 * 
	 * @方法描述: POS单投资批量回款
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/savePlHK")
	public ModelAndView savePlHK(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String ids = RequestUtils.getStringParameter(request, "ids");
		String posCodeArr = RequestUtils.getStringParameter(request, "posCodeArr");
		String tzjeArr = RequestUtils.getStringParameter(request, "tzjeArr");
		String tzsyjeArr = RequestUtils.getStringParameter(request, "tzsyjeArr");
		String hkContentArr = RequestUtils.getStringParameter(request, "hkContentArr");
		String operState = RequestUtils.getStringParameter(request, "operState");
		JSONObject params = new JSONObject();
		params.put("ids", ids);
		params.put("posCodeArr", posCodeArr);
		params.put("tzjeArr", tzjeArr);
		params.put("tzsyjeArr", tzsyjeArr);
		params.put("hkContentArr", hkContentArr);
		params.put("operState", operState);
		params.put("hkUserId", sysUserDetails.getGyh());
		JSONObject result = new JSONObject();
		result.put("success",true);
		boolean isSuc = false;
		try{
			String isReadyPlHk = this.posService.isReadyPlHk(params);
			if("success".equals(isReadyPlHk)){
				String isHasPlHk = this.posService.isHasPlHkByPoscode(params);
				if("success".equals(isHasPlHk)){
					String plHkRes = this.posService.savePosPlHk(params);
					if("success".equals(plHkRes)){
						isSuc = true;
						result.put("msg","批量回款成功！");
					}else if("res_01".equals(plHkRes)){
						isSuc = false;
						result.put("msg","请至少选择一条需要处理的记录！");
					}else if(isReadyPlHk.startsWith("res_02_")){
						String selIndex = isReadyPlHk.substring(isReadyPlHk.lastIndexOf("_") + 1, isReadyPlHk.length());
						isSuc = false;
						result.put("msg","您选中的第"+selIndex+"条记录还未到回款日，无法确认回款！");
					}
				}else if("failure".equals(isHasPlHk)){
					isSuc = false;
					result.put("msg","您的操作有误！");
				}else if("res_01".equals(isHasPlHk)){
					isSuc = false;
					result.put("msg","请至少选择一条需要处理的记录！");
				}else if(isHasPlHk.startsWith("res_02_")){
					String selIndex = isHasPlHk.substring(isHasPlHk.lastIndexOf("_") + 1, isHasPlHk.length());
					isSuc = false;
					result.put("msg","您选中的第"+selIndex+"条已回款，请勿重复操作！");
				}
			}else if("failure".equals(isReadyPlHk)){
				isSuc = false;
				result.put("msg","您的操作有误！");
			}else if("res_01".equals(isReadyPlHk)){
				isSuc = false;
				result.put("msg","请至少选择一条需要处理的记录！");
			}else if(isReadyPlHk.startsWith("res_02_")){
				String selIndex = isReadyPlHk.substring(isReadyPlHk.lastIndexOf("_") + 1, isReadyPlHk.length());
				isSuc = false;
				result.put("msg","您选中的第"+selIndex+"条记录还未到回款日，无法确认回款！");
			}else{
				isSuc = false;
				result.put("msg","还未到回款日，无法确认回款！");
			}
		}catch(Exception e){
			e.printStackTrace();
			isSuc = false;
			result.put("msg","处理失败！");
			logger.info("savePlHK pos单号投资，批量手动回款失败！"+ params.toString());
		}
		result.put("isSuc",isSuc);
		serialize(request, response, result);
		return null;
	}
	
	
	/**
	 * 
	 * @方法描述: pos单，分公司财务发起pos投资撤销申请
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/cxPosTzrxx")
	public ModelAndView cxPosTzrxx(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String start = RequestUtils.getStringParameter(request, "start");
		String limit = RequestUtils.getStringParameter(request, "limit");
		String POS_CODE = RequestUtils.getStringParameter(request, "POS_CODE");
		String POS_OWNER_USER_ID = RequestUtils.getStringParameter(request, "POS_OWNER_USER_ID");
		String POS_OWNER_SJHM = RequestUtils.getStringParameter(request, "POS_OWNER_SJHM");
		String CX_STATE = RequestUtils.getStringParameter(request, "CX_STATE");
		JSONObject params = new JSONObject();
		params.put("start", start);
		params.put("limit", limit);
		params.put("currentUserId", sysUserDetails.getGyh());
		params.put("POS_CODE", POS_CODE);
		params.put("POS_OWNER_USER_ID", POS_OWNER_USER_ID);
		params.put("POS_OWNER_SJHM", POS_OWNER_SJHM);
		params.put("CX_STATE", CX_STATE);
		List<Map<String,Object>> list = posService.queryCzPoscodeTzrxxList(params);
		int count = posService.getCzPoscodeTzrxxCount(params);
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * 
	 * @方法描述: pos单，分公司财务发起申请
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveCxsq")
	public ModelAndView saveCxsq(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String POS_CODE = RequestUtils.getStringParameter(request, "p_POS_CODE");
		String CX_SQ_DATE = RequestUtils.getStringParameter(request, "CX_SQ_DATE");
		String FB_SQ_CONTENT = RequestUtils.getStringParameter(request, "FB_SQ_CONTENT");
		JSONObject params = new JSONObject();
		params.put("currentUserId", sysUserDetails.getGyh());
		params.put("FB_SQ_CONTENT", FB_SQ_CONTENT);
		params.put("POS_CODE", POS_CODE);
		params.put("CX_SQ_DATE", CX_SQ_DATE);
		JSONObject result = new JSONObject();
		result.put("success",true);
		boolean isSuc = false;
		try{
			boolean isHasCq = this.posService.isHasCxsq(params);
			if(isHasCq){
				isSuc = false;
				result.put("msg","该POS单撤销申请已存在，请勿重复操作！");
			}else{
				this.posService.saveCxsq(params);
				isSuc = true;
				result.put("msg","发起撤销申请成功！");
			}
		}catch(Exception e){
			e.printStackTrace();
			isSuc = false;
			result.put("msg","处理失败！");
			logger.info("saveCxsq 分公司财务发起pos单投资撤销申请失败！"+ params.toString());
		}
		result.put("isSuc",isSuc);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * 
	 * @方法描述: pos单，总部财务审核pos投资撤销信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/cxPosTzrxxZbsh")
	public ModelAndView cxPosTzrxxZbsh(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String start = RequestUtils.getStringParameter(request, "start");
		String limit = RequestUtils.getStringParameter(request, "limit");
		String POS_CODE = RequestUtils.getStringParameter(request, "POS_CODE");
		String POS_OWNER_USER_ID = RequestUtils.getStringParameter(request, "POS_OWNER_USER_ID");
		String POS_OWNER_SJHM = RequestUtils.getStringParameter(request, "POS_OWNER_SJHM");
		String CX_STATE = RequestUtils.getStringParameter(request, "CX_STATE");
		JSONObject params = new JSONObject();
		params.put("start", start);
		params.put("limit", limit);
		params.put("currentUserId", sysUserDetails.getGyh());
		params.put("POS_CODE", POS_CODE);
		params.put("POS_OWNER_USER_ID", POS_OWNER_USER_ID);
		params.put("POS_OWNER_SJHM", POS_OWNER_SJHM);
		params.put("CX_STATE", CX_STATE);
		List<Map<String,Object>> list = posService.queryCzPoscodeTzrxxZbshList(params);
		int count = posService.getCzPoscodeTzrxxZbshCount(params);
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", count);
		serialize(request, response, result);
		return null;
	}
	
	/**
	 * 
	 * @方法描述: pos单，保存总部撤销审核结果
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/saveCxsh")
	public ModelAndView saveCxsh(HttpServletRequest request,HttpServletResponse response) throws Exception{
		SysUserDetails sysUserDetails =	(SysUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String POS_CODE = RequestUtils.getStringParameter(request, "p_POS_CODE");
		String CX_STATE = RequestUtils.getStringParameter(request, "ZB_CX_STATE");
		String ZB_SH_CONTENT = RequestUtils.getStringParameter(request, "ZB_SH_CONTENT");
		JSONObject params = new JSONObject();
		params.put("currentUserId", sysUserDetails.getGyh());
		params.put("POS_CODE", POS_CODE);
		params.put("CX_STATE", CX_STATE);
		params.put("ZB_SH_CONTENT", ZB_SH_CONTENT);
		JSONObject result = new JSONObject();
		result.put("success",true);
		boolean isSuc = false;
		try{
			boolean isReadyCxsh = this.posService.isReadyCxsh(params);
			if(!isReadyCxsh){//已审核
				isSuc = false;
				result.put("msg","该POS单撤销申请已审核完毕，请勿重复操作！");
			}else{//可审核
				this.posService.saveCxsh(params);
				isSuc = true;
				result.put("msg","审核成功！");
			}
		}catch(Exception e){
			e.printStackTrace();
			isSuc = false;
			result.put("msg","处理失败！");
			logger.info("saveCxsh 总部财务审核失败！"+ params.toString());
		}
		result.put("isSuc",isSuc);
		serialize(request, response, result);
		return null;
	}
}
